package com.mxd.flink.connector.config;

import org.apache.flink.configuration.ConfigOption;
import org.apache.flink.configuration.ConfigOptions;

/**
 * connector的配置项对象
 * @author rongdi
 * @date 2022/9/18 13:45
 */
public class RedisOptions {

    /**
     * 用于测试用例运行标识，默认为false，如果这个标识为true，则ScanFunction那里数据读取完之后程序会停止
     */
    public static boolean IS_TEST = false;

    /**
     * redis的host
     */
    public static final ConfigOption<String> HOST = ConfigOptions.key("host")
            .stringType()
            .noDefaultValue()
            .withDescription("Optional host for connect to redis");

    /**
     * redis的port
     */
    public static final ConfigOption<Integer> PORT = ConfigOptions.key("port")
            .intType()
            .defaultValue(Integer.valueOf(6379))
            .withDescription("Optional port for connect to redis");


    /**
     * redis的password
     */
    public static final ConfigOption<String> PASSWORD = ConfigOptions.key("password")
            .stringType()
            .noDefaultValue()
            .withDescription("Optional password for connect to redis");

    /**
     * redis的集群节点,英文逗号分割
     */
    public static final ConfigOption<String> CLUSTERNODES = ConfigOptions.key("cluster-nodes")
            .stringType()
            .noDefaultValue()
            .withDescription("Optional nodes for connect to redis cluster");

    /**
     * redis的sentinel模式的master节点的名称
     */
    public static final ConfigOption<String> REDIS_MASTER_NAME = ConfigOptions.key("master.name")
            .stringType()
            .noDefaultValue()
            .withDescription("Optional master.name for connect to redis sentinels");

    /**
     * redis的sentinel模式的info信息
     */
    public static final ConfigOption<String> SENTINELS_INFO = ConfigOptions.key("sentinels.info")
            .stringType()
            .noDefaultValue()
            .withDescription("Optional sentinels.info for connect to redis sentinels");

    /**
     * redis的sentinel模式的密码
     */
    public static final ConfigOption<String> SENTINELS_PASSWORD = ConfigOptions.key("sentinels.password")
            .stringType()
            .noDefaultValue()
            .withDescription("Optional sentinels.password for connect to redis sentinels");

    /**
     * redis的database，一般是0~15
     */
    public static final ConfigOption<Integer> DATABASE = ConfigOptions.key("database")
            .intType()
            .defaultValue(Integer.valueOf(0))
            .withDescription("Optional database for connect to redis");

    /**
     * redis的命令，如获取redis的get、hget，写入redis的put
     */
    public static final ConfigOption<String> COMMAND = ConfigOptions.key("command")
            .stringType()
            .noDefaultValue()
            .withDescription("Optional command for connect to redis");
    /**
     * redis的部署模式，single、cluster、sentinel
     */
    public static final ConfigOption<String> REDISMODE = ConfigOptions.key("redis-mode")
            .stringType()
            .noDefaultValue()
            .withDescription("Optional redis-mode for connect to redis");
    /**
     * 1、redis需要访问的key，比如数据是以某个固定的key存放在redis里，值是一个list
     * 2、redis执行lpush、rpush、sadd、hset等sink使用的命令时的key
     */
    public static final ConfigOption<String> KEY = ConfigOptions.key("key")
            .stringType()
            .noDefaultValue()
            .withDescription("Optional key for scan data from redis");

    /**
     * 连接redis的超时时间，单位毫秒
     */
    public static final ConfigOption<Integer> TIMEOUT = ConfigOptions.key("timeout")
            .intType()
            .defaultValue(Integer.valueOf(4000))
            .withDescription("Optional timeout for connect to redis");
    /**
     * 连接redis的连接池的最大连接数
     */
    public static final ConfigOption<Integer> MAXTOTAL = ConfigOptions.key("max-total")
            .intType()
            .defaultValue(Integer.valueOf(4))
            .withDescription("Optional maxTotal for connect to redis");
    /**
     * 连接redis的连接池的最大空闲数
     */
    public static final ConfigOption<Integer> MAXIDLE = ConfigOptions.key("max-idle")
            .intType()
            .defaultValue(Integer.valueOf(2))
            .withDescription("Optional maxIdle for connect to redis");
    /**
     * 连接redis的连接池的最小空闲数
     */
    public static final ConfigOption<Integer> MINIDLE = ConfigOptions.key("min-idle")
            .intType()
            .defaultValue(Integer.valueOf(1))
            .withDescription("Optional minIdle for connect to redis");
    /**
     * 格式化数据格式，如json、csv
     */
    public static final ConfigOption<String> FORMAT = ConfigOptions.key("format")
            .stringType()
            .noDefaultValue()
            .withDescription("Optional format for scan data from redis");

    /**
     * 像LPOP、BLPOP、RPOP、BRPOP这种命令每次从redis拿到数据的条数
     */
    public static final ConfigOption<Long> BATCH_FETCH_ROWS = ConfigOptions.key("batch-fetch-rows")
            .longType()
            .defaultValue(Long.valueOf(100L))
            .withDescription("Optional  max rows of cache for query redis");
    /**
     * 作为维表lookup模式，缓存在内存中的数据的最大条数
     */
    public static final ConfigOption<Long> LOOKUP_CACHE_MAX_ROWS = ConfigOptions.key("lookup.cache.max-rows")
            .longType()
            .defaultValue(Long.valueOf(-1L))
            .withDescription("Optional  max rows of cache for query redis");
    /**
     * 作为维表lookup模式，缓存在内存中的数据的ttl超时时间，单位秒
     */
    public static final ConfigOption<Long> LOOKUP_CHCHE_TTL = ConfigOptions.key("lookup.cache.ttl")
            .longType()
            .defaultValue(Long.valueOf(-1L))
            .withDescription("Optional ttl of cache for query redis");
    /**
     * 作为维表lookup模式，查找数据的失败重试次数
     */
    public static final ConfigOption<Integer> LOOKUP_MAX_RETRIES = ConfigOptions.key("lookup.max-retries")
            .intType()
            .defaultValue(Integer.valueOf(1))
            .withDescription("Optional max retries of cache for query redis");
    /**
     * 作为维表lookup模式，查找数据是否加载所有，主要是针对hget命令，如：HGET KEY_NAME FIELD_NAME
     * 是否根据key查出所有field的值，这里可以根据实际hash表的大小决定是否要查询所有出来缓存起来
     */
    public static final ConfigOption<Boolean> LOOKUP_CACHE_LOAD_ALL = ConfigOptions.key("lookup.cache.load-all")
            .booleanType()
            .defaultValue(Boolean.valueOf(false))
            .withDescription("Optional if load all elements into cache for query");

    /**
     * lookup join 异步开关，为true则会使用异步算子做查询
     */
    public static final ConfigOption<Boolean> LOOKUP_ASYNC_ENABLED = ConfigOptions.key("lookup.async.enabled")
            .booleanType()
            .defaultValue(Boolean.valueOf(false))
            .withDescription("Optional if async enabled use AsyncRedisLookupFunction");
    /**
     * redis作为sink源时，最大重试次数
     */
    public static final ConfigOption<Integer> SINK_MAX_RETRIES = ConfigOptions.key("sink.max-retries")
            .intType()
            .defaultValue(Integer.valueOf(1))
            .withDescription("Optional max retries of cache sink redis");
    /**
     * redis作为sink源时，sink的并行数，默认并行度为核心数
     */
    public static final ConfigOption<Integer> SINK_PARALLELISM = ConfigOptions.key("sink.parallelism")
            .intType()
            .defaultValue(Runtime.getRuntime().availableProcessors())
            .withDescription("Optional parrallelism for sink redis");

    /**
     * redis作为sink源时，sink的数据保存在redis的ttl超时时间，单位秒
     */
    public static final ConfigOption<Integer> SINK_KEY_TTL = ConfigOptions.key("sink.key.ttl")
            .intType()
            .defaultValue(-1)
            .withDescription("Optional ttl for sink redis");

}
